package com.bjsxt.homework2;

public class Printer {

    //1~60的数字
    int number = 1;

    //记录线程状态，status % 3的结果代表几号线程输出
    int status = 0;

    public synchronized void print() {
        //线程名称：0~2
        int threadName = Integer.parseInt(Thread.currentThread().getName());

        while ((status % 3) != threadName) {
            try {
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        System.out.print("线程" + threadName + "输出：");
        for (int i = 0; i < 5; i++) {
            System.out.print(number++ + " ");
        }
        System.out.println();

        status++;

        this.notifyAll();
    }
}
